package visiopuce.ui.tree;

import java.util.List;

import org.eclipse.swt.graphics.Image;

import visiopuce.objets.Alteration;
import visiopuce.objets.Puce;
import visiopuce.service.AlterationService;
import visiopuce.service.AlterationServiceImpl;

public class PuceNode extends TreeNode {

	private Puce puce;

	public PuceNode(Puce puce) {
		this(null, puce);
	}

	public PuceNode(ITreeNode parent, Puce puce) {
		super(parent);
		this.puce = puce;
	}

	public String getName() {
		String chaine;
		if (puce.getTypePuce() == null){
			chaine = " n°" + puce.getIdPuce();
		}
		else {
			chaine =  puce.getTypePuce().getLibelle() + " n°" + puce.getIdPuce();
		}
		return chaine;
	}

	public Image getImage() {
		// return new Image(new Display(),"icons/array.jpg");
		return null;
	}

	@Override
	protected void createChildren(List children) {
		AlterationService alterationService = AlterationServiceImpl
				.getInstance();
		List<Alteration> alterations = alterationService.findAllByidPuce(puce
				.getIdPuce());
		for (Alteration alteration : alterations) {
			children.add(new AlterationNode(this, alteration));
		}
	}

	public Puce getPuce() {

		return puce;
	}

}